<script setup>
import { ref } from 'vue'
import { auditCourseService } from '@/api/course.js'
const dialogVisible = ref(false)
const formRef = ref()
const audit = ref({
  id: '',
  status: '',
  mind: ''
})
const emit = defineEmits(['success'])

const open = async (id, status) => {
  dialogVisible.value = true
  audit.value = { id, status, mind: '' }
}

defineExpose({
  open
})

const onSubmit = async () => {
  dialogVisible.value = false
  await auditCourseService(audit.value)
  ElMessage({ type: 'success', message: '审核成功' })
  emit('success')
}

const rules = {
  mind: [{ required: true, message: '审核意见不能为空', trigger: 'blur' }]
}
</script>

<template>
  <el-dialog v-model="dialogVisible" title="审核意见" width="45%">
    <el-form
      ref="formRef"
      :model="audit"
      :rules="rules"
      label-width="100px"
      style="padding-right: 30px"
    >
      <el-form-item label="审核意见" prop="mind">
        <el-input
          v-model="audit.mind"
          style="width: 100%"
          :rows="10"
          type="textarea"
          placeholder="请输入相关审核意见"
          show-word-limit
          maxlength="250"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="onSubmit"> 确认 </el-button>
      </span>
    </template>
  </el-dialog>
</template>
